<template>
	<div>
		<div class="box">
			<uni-forms
				ref="form"
				:model="financialProfitCalcResult"
				validate-trigger="bind"
				:label-position="state == 'write' ? 'top' : 'left'"
				label-width="auto">
				<FromItem
					state="readonly"
					label="租赁利润"
					name="leasingProfit">
					{{ computedData.leasingProfit() }}
				</FromItem>
				<FromItem
					state="readonly"
					label="处置利润"
					name="disposalProfit">
					{{ computedData.disposalProfit() }}
				</FromItem>
				<FromItem
					state="readonly"
					label="利息支出"
					name="interestExpense">
					{{ computedData.interestExpense() }}
				</FromItem>
				<FromItem
					state="readonly"
					label="税前利润"
					name="profitBeforeTax">
					{{ computedData.profitBeforeTax() }}
				</FromItem>
				<FromItem state="readonly" label="净利润" name="netProfit">
					{{ computedData.netProfit() }}
				</FromItem>
				<FromItem
					state="readonly"
					label="租赁毛利率"
					name="totalLeasingProfit">
					{{ computedData.totalLeasingProfit() }}
				</FromItem>
			</uni-forms>
		</div>
	</div>
</template>

<script>
	import * as app from '@/api/index.js';
	import * as apis from '@/api/quota/apply/api.js';
	import * as utils from '@/pages/quota/libs/utils.js';
	import FromItem from '../formItem/index.vue';
	export default {
		name: '',
		components: { FromItem },
		dicts: [],
		props: {},
		inject: [
			'details_provide',
			'config_provide',
			'deptList_provide',
			'state_provide',
			'index_provide',
			'planDicts_provide',
			'fromtype_provide',
		],
		data() {
			return {};
		},
		computed: {
			details() {
				return this.details_provide();
			},
			config() {
				return this.config_provide();
			},
			deptList() {
				return this.deptList_provide();
			},
			planDicts() {
				return this.planDicts_provide();
			},
			state() {
				return this.state_provide();
			},
			fromtype() {
				return this.fromtype_provide();
			},

			index() {
				return this.index_provide();
			},
			currentInfoData() {
				return this.details.productList?.[this.index] ?? {};
			},
			firstInfoData() {
				return this.details.productList?.[0] ?? {};
			},
			calcSnapshoot() {
				if (
					this.currentInfoData.calcSnapshoot &&
					typeof this.currentInfoData.calcSnapshoot == 'string'
				) {
					return JSON.parse(this.currentInfoData.calcSnapshoot) || {};
				} else {
					return this.currentInfoData.calcSnapshoot || {};
				}
			},
			financialProfitCalcResult() {
				return this.calcSnapshoot?.financialProfitCalcResult ?? {};
			},
			computedData() {
				return {
					leasingProfit: () => {
						let row = this.financialProfitCalcResult;
						let price = row?.leasingProfit * 1;
						return Number.isFinite(price)
							? this.format_thousand(price?.toFixed(2))
							: '-';
					},
					disposalProfit: () => {
						let row = this.financialProfitCalcResult;
						let price = row?.disposalProfit * 1;
						return Number.isFinite(price)
							? this.format_thousand(price?.toFixed(2))
							: '-';
					},
					interestExpense: () => {
						let row = this.financialProfitCalcResult;
						let price = row?.interestExpense * 1;
						return Number.isFinite(price)
							? this.format_thousand(price?.toFixed(2))
							: '-';
					},
					profitBeforeTax: () => {
						let row = this.financialProfitCalcResult;
						let price = row?.profitBeforeTax * 1;
						return Number.isFinite(price)
							? this.format_thousand(price?.toFixed(2))
							: '-';
					},
					netProfit: () => {
						let row = this.financialProfitCalcResult;
						let price = row?.netProfit * 1;
						return Number.isFinite(price)
							? this.format_thousand(price?.toFixed(2))
							: '-';
					},
					totalLeasingProfit: () => {
						let row = this.financialProfitCalcResult;
						let price = utils.toNumberRide(
							row?.leasingGrossProfitMargin,
							100,
						);
						if (isNaN(price)) return '-';
						let priceT = this.format_thousand(price?.toFixed(2));
						return priceT ? priceT + '%' : '-';
					},
				};
			},
		},
		watch: {},
		filters: {},
		created() {},
		mounted() {},
		methods: {},
	};
</script>

<style lang="scss" scoped>
	.box {
		// margin: 20rpx;
		// padding: 20rpx;
		padding-top: 20rpx;
		background-color: #fff;
		border-radius: 8rpx;
		.title {
			border-bottom: 1px solid #e9e9e9;
			font-weight: 500;
			padding-bottom: 10rpx;
			margin-bottom: 10rpx;
		}
	}
</style>
